/*
 * Flashlib - QB9 common Flash library
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.qb9.flashlib.prototyping.shapes
{
	import com.qb9.flashlib.geom.Anchor;
	import com.qb9.flashlib.math.QMath;

	// TODO: Add customizable angle

	public class Parallelogram extends BasicShape
	{
		private var b:Number;
		private var h:Number;
		private var a:int;
		
		public function Parallelogram(base:Number, height:Number, angle:int=45, config:Object=-1, anchor:Anchor=null)
		{
			b = base;
			h = height;
			a = angle;
			
			super(config, anchor);
		}
		
		protected override function draw() : void
		{
			var o:Number = h * Math.tan(QMath.deg2rad(a));
			var t:Number = b + o;
			var dx:Number = -t * anchor.u;
			var dy:Number = -h * anchor.v;
			
			g.moveTo(o + dx, 0 + dy);
			g.lineTo(t + dx, 0 + dy);
			g.lineTo(b + dx, h + dy);
			g.lineTo(0 + dx, h + dy);
			g.lineTo(o + dx, 0 + dy);
		}
	}
}